package cn.edu.xjtu.nbrash.xbarsuite;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import cn.edu.xjtu.nbrash.xbarsuite.floatbutton.RashFloatButton;
import cn.edu.xjtu.nbrash.xbarsuite.presms.RashPreSmsActivity;
import cn.edu.xjtu.nbrash.xbarsuite.terry.EncodeContact;
import cn.edu.xjtu.nbrash.xbarsuite.terry.EncodeEmail;
import cn.edu.xjtu.nbrash.xbarsuite.terry.EncodePhone;
import cn.edu.xjtu.nbrash.xbarsuite.terry.EncodeSMS;
import cn.edu.xjtu.nbrash.xbarsuite.terry.EncodeText;
import cn.edu.xjtu.nbrash.xbarsuite.terry.EncodeWifiConfig;

public class RashMoreActivity extends Activity {

	private List<Map<String, Object>> list;
	private Map<Map<String, Object>, Intent> intents;
	private ListView listView;

	private static final String ICON = "icon";
	private static final String TITLE = "title";

	private void init() {
		intents = new LinkedHashMap<Map<String, Object>, Intent>();

		this.putIntents(R.drawable.float_button,
				R.string.title_activity_rash_float_button,
				RashFloatButton.class);
		this.putIntents(R.drawable.sms_encode_ic,
				R.string.title_activity_presms, RashPreSmsActivity.class);
		this.putIntents(R.drawable.about_more_ic,
				R.string.title_activity_about, AboutActivity.class);
	}

	private void putIntents(int rsidIC, int rsidTitle, Class<?> cls) {
		Map<String, Object> map = new HashMap<>();
		map.put(ICON, rsidIC);
		map.put(TITLE, getString(rsidTitle));

		intents.put(map, new Intent(this, cls));
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_rash_more);

		listView = (ListView) findViewById(R.id.list_more);
		init();

		list = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> map : intents.keySet()) {
			list.add(map);
		}

		listView.setAdapter(new SimpleAdapter(this, list, R.layout.more_item,
				new String[] { ICON, TITLE }, new int[] { R.id.more_item_ic,
						R.id.more_item_title }));

		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				startActivity(intents.get(list.get(position)));
			}
		});

	}

}
